package com.oppo.controller;


import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.github.xiaoymin.knife4j.annotations.ApiOperationSupport;

import com.oppo.entity.ProjectProfitBasis;
import com.oppo.result.BusinessResult;
import com.oppo.service.ProjectProfitBasisService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiResponse;
import io.swagger.annotations.ApiResponses;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import java.io.Serializable;
import java.util.List;


/**
 * 损益基础表(t_project_profit_basis)表控制层
 *
 * @author makejava
 * @since 2022-01-28 16:23:03
 */
@Api(value = "损益基础表(t_project_profit_basis)表控制层",
        tags = "损益基础表控制层")
@RestController
@RequestMapping(value = "/projectProfitBasis")
public class ProjectProfitBasisController {

    /**
     * 服务对象
     */
    @Resource
    private ProjectProfitBasisService projectProfitBasisService;


    /**
     * 查询所有数据
     *
     * @return 所有数据
     */
    @ApiOperation("查询所有数据")
    @GetMapping(value = "getAll")
    public BusinessResult getAll() {
        return BusinessResult.success(this.projectProfitBasisService.list());
    }


    /**
     * 分页查询所有数据
     *
     * @param page               分页对象
     * @param projectProfitBasis 查询实体
     * @return 所有数据
     */
    @ApiOperation("分页查询所有数据")
    @GetMapping(value = "/selectAll")
    public BusinessResult selectAll(Page<ProjectProfitBasis> page, ProjectProfitBasis projectProfitBasis) {
        return BusinessResult.success(this.projectProfitBasisService.page(page, new QueryWrapper<>(projectProfitBasis)));
    }


    /**
     * 通过主键查询单条数据
     *
     * @param id 主键
     * @return 单条数据
     */
    @ApiOperation("通过主键查询单条数据")
    @ApiOperationSupport(author = "steve,email=1518109600@qq.com")
    @ApiResponses(value = {@ApiResponse(code = 200, message = "接口返回成功状态"),
            @ApiResponse(code = 500, message = "接口返回未知错误，请联系开发人员调试")
    })
    @GetMapping(value = "/{id}")
    public BusinessResult selectOne(@PathVariable Serializable id) {
        return BusinessResult.success(this.projectProfitBasisService.getById(id));
    }


    /**
     * 新增数据
     *
     * @param projectProfitBasis 实体对象
     * @return 新增结果
     */
    @ApiOperation("新增数据")
    @PostMapping(value = "/insert")
    public BusinessResult insert(@RequestBody ProjectProfitBasis projectProfitBasis) {
        return BusinessResult.success(this.projectProfitBasisService.save(projectProfitBasis));
    }


    /**
     * 修改数据
     *
     * @param projectProfitBasis 实体对象
     * @return 修改结果
     */
    @ApiOperation("修改数据")
    @PutMapping(value = "/update")
    public BusinessResult update(@RequestBody ProjectProfitBasis projectProfitBasis) {
        return BusinessResult.success(this.projectProfitBasisService.updateById(projectProfitBasis));
    }


    /**
     * 删除数据
     *
     * @param idList 主键列表
     * @return 删除结果
     */
    @ApiOperation("删除数据")
    @DeleteMapping(value = "delete")
    public BusinessResult delete(@RequestParam("idList") List<Long> idList) {
        return BusinessResult.success(this.projectProfitBasisService.removeByIds(idList));
    }

}
